﻿using System;
using System.Collections.Generic;
using System.Windows;
using Caliburn.Micro;
using Infrastructure;
using Microsoft.Phone.Controls;
using SverigesRadio.SverigesRadioApp.Business;
using SverigesRadio.SverigesRadioApp.WindowsPhoneApplication.Audio;
using SverigesRadio.SverigesRadioApp.WindowsPhoneApplication.ViewModels.Player;
using SverigesRadio.SverigesRadioApp.WindowsPhoneApplication.ViewModels.Programs;

namespace SverigesRadio.SverigesRadioApp.WindowsPhoneApplication
{
    public class Bootstrapper : PhoneBootstrapper
    {
        private PhoneContainer container;

        protected override void Configure()
        {
            container = new PhoneContainer(RootFrame);
            container.RegisterPhoneServices();

            container.PerRequest<MainPageViewModel>();
            container.PerRequest<ProgramsPageViewModel>();
            container.PerRequest<ProgramPageViewModel>();
            container.PerRequest<PlayerPageViewModel>();
            container.PerRequest<ProgramBroadcastArchivePageViewModel>();

            container.RegisterPerRequest(typeof (IDataContext), null, typeof (DataContext));
            container.RegisterPerRequest(typeof(IAudioPlayer), null, typeof(AudioPlayer));

        }

        protected override PhoneApplicationFrame CreatePhoneApplicationFrame()
        {
            return new TransitionFrame();
        }

        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            RootFrame.Style = (Style)Application.Resources["mainFrameStyle"];
        }

        protected override object GetInstance(Type service, string key)
        {
            return container.GetInstance(service, key);
        }

        protected override IEnumerable<object> GetAllInstances(Type service)
        {
            return container.GetAllInstances(service);
        }

        protected override void BuildUp(object instance)
        {
            container.BuildUp(instance);
        }  

    }
}
